package com.xuecheng.search.config;

import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author Sober_wxy
 * @date 2022/7/25 15:36
 */
@Configuration
public class ElasticSearchConfig {

        @Value("${xuecheng.elasticsearch.hostlist}")
        private String hostlist;

        /**
         * 创建Client对象存入容器
         * @return RestHighLevelClient
         */
        @Bean
        public RestHighLevelClient restHighLevelClient(){
                HttpHost httpHost = HttpHost.create(hostlist);
                return new RestHighLevelClient(RestClient.builder(httpHost));
        }
}
